// 消息记录页面store

import { defineStore } from 'pinia';
import { reactive } from 'vue';
import { getDict } from '/@/api/comprehensive/reconciliation';

export const useMessageLogRouteStore = defineStore('messageLogRoute', () => {
  const allSelectOptions = reactive({
    MessageStatusId: [],
    SmsBusinessType: [],
  });

  // 根据字段类型值获取对应字典并存储起来复用
  async function getSelectOptionsByDictType(key: string) {
    if (allSelectOptions[key] && allSelectOptions[key].length > 0) return;
    const params = { key };
    const res = await getDict(params);
    if (res.code === 0) {
      allSelectOptions[key] =
        (res.data &&
          res.data.map((item) => ({ label: item.display_name, value: item.value_member }))) ??
        [];
    }
  }

  return {
    allSelectOptions,
    getSelectOptionsByDictType,
  };
});
